<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="description" content="C1N短网址服务平台，随心所欲定制域名，定制网址。c1n.cn为您提供专业、稳定、安全、快速、便捷的短网址服务。轻松帮助您把冗长网址缩短为10个字符以内的短网址,方便您分享和使用。" />
	<meta name="keywords" content="C1N短网址服务平台" />
	<meta name="apple-mobile-web-app-capable" content="yes">
    <title>C1N短网址服务平台</title>
    <link rel="shortcut icon" href="./img/logo1.png">
    <link rel="stylesheet" type="text/css" href="css/login.css">
</head>
<body>
    <div id="pageName" hidden>resetPassword</div>
    <div class="board">
        <div class="title">
            <div class="picTitle">重置密码</div>
        </div>
        <div class="form">
            <input type="text" id="user" placeholder="用户名"/>
            <input type="text" id="mail" placeholder="邮箱"/>
            <div class="code clearfix">
                <input type="text" id="code" placeholder="验证码"/>
                <button class="active">发送验证码</button>
            </div>
            <input type="password" id="pwd" placeholder="新密码"/>
            <input type="password" id="rePwd" placeholder="请再次确认新密码"/>
            <button >确认</button>
        </div>
    </div>

    <!-- 弹窗 -->
    <div class="notePop err" hidden><b></b><i>x</i></div>

    <script  type="text/javascript" src="js/jquery.min.js"></script>
    <script  type="text/javascript" type="text/javascript" src="js/md5.js"></script>
    <script  type="text/javascript" src="js/common.js" ></script>
    <script  type="text/javascript" src="js/login.js"></script>
</body>
</html>

<script>
    $(function(){
        $(".form .code button").click(function(){
            $(this).attr("disabled","disabled").removeClass("active").text("60s");
            var user = $.trim($("#user").val());
            var mail = $.trim($("#mail").val());
            if(!beforeGetCode(user,mail)){
                $(this).attr("disabled",false).addClass("active").text("发送验证码");
                return;
            }
            getCode(user,mail)
        })

        // 用户名和邮箱验证
        function beforeGetCode(user,mail){
            if(!(user && mail)){
                alertTip("err","请先填写用户名和邮箱",400,4000);
                return;
            }
            var re = /^[a-zA-Z0-9]{3,18}$/;
            if(! re.test(user)) {
                alertTip("err","用户名需为4到18位数字和字母组成",400,4000)
                return false;
            }
            var re1 = /^[\.a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
            if(! re1.test(mail)) {
                alertTip("err","邮箱格式不正确",400,4000)
                return false;
            }
            return true;
        }
        
        // 请求验证码
        function getCode(user,mail){
            var data = {
                user:user,
                mail:mail
            };
            ajaxPost("/manage/user/verificationCode",data,function(data){
                var code = data.code;
                var msg = data.msg;
                if(!code){
                    alertTip("success","验证码邮件已发送，请前往邮箱查看! 10分钟内有效",400,4000);
                    timeRun(60);
                }else{
                    alertTip("err",msg,400,4000);
                    $(".form .code button").attr("disabled",false).addClass("active").text("发送验证码");
                };
            });
        }
        
        // 倒计时动画
        // var s = 10;
        function timeRun(time){
            $(".form .code button").text(time+"s")
            var s = time;
            var time10 = setInterval(function(){
                if(s == 0){
                    clearInterval(time10)
                    $(".form .code button").attr("disabled",false).addClass("active").text("发送验证码");
                    return false;
                }
                s = s - 1;
                $(".form .code button").text(s+"s");
            }, 1000);
        }
        

    })
</script>